<template>
  <div>
    <div class="home-title">
      <div class="felxdiv">
        <p><i class="el-icon-document-copy"></i></p>
        <div>
          <p>总订单</p>
          <p>{{homeData.totalOrder}}</p>
        </div>
      </div>
      <div class="felxdiv">
        <p><i class="el-icon-coin"></i></p>
        <div>
          <p>总销售额</p>
          <p>{{homeData.totalAmount}}</p>
        </div>
      </div>
      <div class="felxdiv">
        <p><i class="el-icon-document-checked"></i></p>
        <div>
          <p>今日订单数</p>
          <p>{{homeData.todayOrder}}</p>
        </div>
      </div>
      <div class="felxdiv">
        <p><i class="el-icon-s-finance"></i></p>
        <div>
          <p>总今日销售额</p>
          <p>{{homeData.totayAmount}}</p>
        </div>
      </div>
    </div>
    <div class="main" ref="chartRef"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import { getOrderTotal } from "@/api/order";
export default {
  data(){
    return{
      homeData: {
        xData: [],
        orderData: [],
        amountData: [],
        totalOrder: 0,
        totalAmount: 0,
        todayOrder: 0,
        totayAmount: 0,
      },
    }
  },
methods:{
  async Getdata(){
    let res = await getOrderTotal()
    console.log(res);
    this.homeData=res.data
     //处理数据
      let series = [
        {
          type: "line",
          name: "金额数据",
          data: this.homeData.amountData,
        },
        {
          type: "line",
          name: "订单数据",
          data: this.homeData.orderData,
        },
      ];
      let xData = this.homeData.xData
     //画图
      this.renderLine({
        series,
        xData,
      });
  },
  //画折线图
  renderLine(obj){
    // 基于准备好的dom，初始化echarts实例
      let myChart = echarts.init(this.$refs.chartRef);
      let options = {
        title: {
          text: "Stacked Line",
        },
        tooltip: {
          trigger: "axis",
        },
        legend: {},
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: obj.xData,
        },
        yAxis: {
          type: "value",
        },
        series: obj.series,
      };
      // 绘制图表
      myChart.setOption(options);
  }
},
created(){
  this.Getdata()
}
};
</script>

<style lang="scss" scoped>
.main{
  margin-top: 20px;
  background-color: #fff;
  width: 100%; 
  height: 400px
}
.home-title {
  display: flex;
  justify-content: space-around;
  padding-top: 25px;
  .felxdiv {
    width: 285px;
    height: 135px;
    background-color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .el-icon-document-copy,.el-icon-coin,.el-icon-document-checked,.el-icon-s-finance {
      font-size: 100px;
      margin-left: 30px;
      color: #aaa;
    }
    div {
      margin-right: 25px;
      display: flex;
      flex-direction: column;
      align-items: center;
      p:nth-child(1) {
        color: #eed076;
        font-size: 18px;
      }
      p:nth-child(2) {
        font-size: 16px;
        font-weight: 700;
      }
    }
  }
}
</style>
